package cn.jbolt.core.Interceptor.reqlimit;

public class JBoltRateResult {
    public static final String DEFAULT_MSG = "操作过于频繁，请稍后重试";
    private static final String CHECK_EXCEPTION_DEFAULT_MSG = "系统限流检测异常";
    private static final String NO_IP_MSG = "系统限流检测异常";
    public static final JBoltRateResult PASS = JBoltRateResult.pass();
    public static final JBoltRateResult NOT_PASS = JBoltRateResult.notPass();
    public static final JBoltRateResult CHECK_EXCEPTION = JBoltRateResult.checkException();
    public static final JBoltRateResult NO_IP = JBoltRateResult.noIp();
    private boolean isPass;
    private String msg;
    public static JBoltRateResult pass(){
        return new JBoltRateResult(true,null);
    }
    public static JBoltRateResult notPass(String msg){
        return new JBoltRateResult(false,msg==null?DEFAULT_MSG:msg);
    }
    public static JBoltRateResult notPass(){
        return new JBoltRateResult(false,DEFAULT_MSG);
    }
    private static JBoltRateResult checkException(){
        return notPass(CHECK_EXCEPTION_DEFAULT_MSG);
    }
    private static JBoltRateResult noIp(){
        return notPass(NO_IP_MSG);
    }
    private JBoltRateResult(boolean isPass) {
        this.isPass = isPass;
    }
    private JBoltRateResult(boolean isPass, String msg) {
        this.isPass = isPass;
        this.msg = msg;
    }

    public boolean isPass() {
        return isPass;
    }
    public boolean isNotPass() {
        return !isPass;
    }

    public void setPass(boolean pass) {
        isPass = pass;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
